home *** CD-ROM | disk | FTP | other *** search
- <?php
- ////////////////////////////////////////////////////////////////////////////////
- // <!--Copyright (c) 2005 Pure Networks Inc. All rights reserved.-->
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Build: 3.0.6121.0 (Stable)
- // $Revision: #3 $
- //
- $sNavLocation = "download";
- ob_start();
- require "_session_common.php";
- ob_get_clean();
- //require "styles/" . $sStyleFamily . "/default.inc";
- require "styles/" . $sStyleFamily . "/" . $sStyleName . "/colors.php";
- $errorOccurred = 0;
- $errorText = "";
- $sShare = "";
- $sPath = "";
- $sNetworkName = "";
- ///////////////////////////////////////////////////
- // Make sure that we have a valid share passed in.
- ///////////////////////////////////////////////////
- if (!isset($_GET['share']))
- {
- $errorOccurred = 200;
- log_activity("QS check", "failure", return_error_text(200, "", $arErrors));
- }
- else
- {
- $sShare = $_GET['share'];
- log_activity("download share", "info", $sShare);
- }
- ///////////////////////////////////////////////////
- // Make sure that we have a valid path passed in.
- ///////////////////////////////////////////////////
- if ($errorOccurred == 0)
- {
- if (!isset($_GET['path']))
- {
- $errorOccurred = 201;
- log_activity("QS check", "failure", return_error_text(201, "", $arErrors));
- }
- else
- {
- $sPath = urlDecodeString($_GET['path']);
- log_activity("download path", "info", $sPath);
- }
- }
- ///////////////////////////////////////////////////
- // Make sure we have a valid filename passed in.
- ///////////////////////////////////////////////////
- if ($errorOccurred == 0)
- {
- if (!isset($_GET['fileName']))
- {
- $errorOccurred = 204;
- log_activity("QS check", "failure", return_error_text(204, "", $arErrors));
- }
- else
- {
- $sFile = urlDecodeString($_GET['fileName']);
- $sPath .= "\\" . $sFile;
- log_activity("download filename", "info", $sPath);
- }
- }
- ///////////////////////////////////////////////////
- // Are we going to force download of the file?
- ///////////////////////////////////////////////////
- switch ($_GET['action'])
- {
- case "open":
- case "save":
- case "slideshow":
- ini_set ( "max_execution_time", "1800" );
- $sAction = $_GET['action'];
- break;
- case "thumbnail":
- ini_set ( "max_execution_time", "10" );
- $sAction = "systemcreatedimage";
- $iImageHeight = $iThumbnailHeight;
- $iImageWidth = $iThumbnailWidth;
- break;
- case "sharethumbnail":
- $sAction = $_GET['action'];
- $iImageHeight = $iThumbnailHeight;
- $iImageWidth = $iThumbnailWidth;
- break;
- case "slideimage":
- $sAction = "systemcreatedimage";
- $iImageHeight = $iSlideshowHeight;
- $iImageWidth = $iSlideshowWidth;
- break;
- case "detailsview":
- $sAction = "systemcreatedimage";
- $iImageHeight = $iMidSizeHeight;
- $iImageWidth = $iMidSizeWidth;
- break;
- default:
- ini_set ( "max_execution_time", "1800" );
- $sAction = "open";
- }
- ///////////////////////////////////////////////////
- // Force files with specific extensions to behave
- // specific ways regardless of requested action
- ///////////////////////////////////////////////////
- $fileExtension = strtolower(strrchr($sFile, "."));
- switch ($fileExtension)
- {
- case ".exe":
- if ($sAction != "systemcreatedimage")
- {
- $sAction = "save";
- }
- break;
- }
- ///////////////////////////////////////////////////
- // Let's try to see if we can open the share
- ///////////////////////////////////////////////////
- try
- {
- $nmSharedPlace = $nmNetworkLib->OpenShare($sShare);
- }
- catch(Exception $ex)
- {
- log_activity("Attempting nmNetworkLib->OpenShare($sShare)", "exception", $ex->getMessage());
- gotoAbs('/error/305/return');
- exit();
- }
- ///////////////////////////////////////////////////
- // double check the access level and react
- ///////////////////////////////////////////////////
- try
- {
- $sAccessLevel = $nmSharedPlace->AccessLevel;
- }
- catch(Exception $ex)
- {
- log_activity("Attempting nmSharedPlace->AccessLevel", "exception", $ex->getMessage());
- gotoAbs('/error/305/return');
- exit();
- }
- switch ($sAccessLevel)
- {
- case 0:
- ///////////////////////////////////////////////////
- // Public share, show away.
- ///////////////////////////////////////////////////
- break;
- case 1:
- if (!$bLoggedIn)
- {
- ///////////////////////////////////////////////////
- // Private share and user is not logged in, go away.
- ///////////////////////////////////////////////////
- log_activity("private folder request without session", "error", return_error_text(308, "", $arErrors));
- gotoAbs('/login/308');
- exit();
- }
- break;
- case 2:
- ///////////////////////////////////////////////////
- // Restricted share, go away.
- ///////////////////////////////////////////////////
- log_activity("restricted share request", "error", return_error_text(310, "", $arErrors));
- gotoAbs('/login/310');
- exit();
- break;
- default:
- log_activity("Undefined share access level", "error", return_error_text(311, "", $arErrors));
- gotoAbs('/login/311');
- exit();
- }
- ///////////////////////////////////////////////////
- // Make sure the file exists
- ///////////////////////////////////////////////////
- if (!file_exists($sPath))
- {
- $errorOccurred = 342;
- log_activity("download:" . $sPath, "failure", return_error_text(342, "", $arErrors));
- }
- if ($errorOccurred == 0)
- {
- if ($nmSharedPlace->GetFileTypeDescription($sPath) <> "Internet Shortcut" || $sAction == "systemcreatedimage")
- {
- ///////////////////////////////////////////////////
- // We have a non shortcut file, let's start getting the headers ready
- ///////////////////////////////////////////////////
- if ($sAction == "open" || $sAction == "systemcreatedimage")
- {
- if ($sAction == "systemcreatedimage")
- {
- ///////////////////////////////////////////////////
- // get the path to the thumbnail and use it to deliver image
- ///////////////////////////////////////////////////
- try
- {
- $imgLocation = $nmRaManager->GetThumbnailForFile($sPath, $iImageWidth,
- $iImageHeight, $sContentBackground );
- }
- catch(com_exception $ex)
- {
- // An error occurred while attempting to get the image, display bad image pic
- $imgLocation = "styles/" . $sStyleFamily . "/" . $sStyleName . "/image.broken.gif";
- $imgMode = "Bad";
- }
- $sPath = $imgLocation;
- }
- header("Content-Disposition: inline; filename=\"" . basename($sPath) . "\"");
- try
- {
- $contentType = $nmSharedPlace->GetContentType(basename($sPath));
- }
- catch(com_exception $ex)
- {
- // An error occurred while attempting to get the content-type. Assume octet-stream as
- // unknown type
- $contentType = "application/octet-stream";
- }
- header("Content-Type: " . $contentType);
- }
- else
- {
- if ($sAction == "sharethumbnail")
- {
- header("Content-Disposition: inline; filename=\"" . basename($sPath) . "\"");
- header("Content-Type: " . $nmSharedPlace->GetContentType(basename($sPath)));
- }
- else
- {
- header("Content-Disposition: attachment; filename=\"" . basename($sPath) . "\"");
- header("Content-Type: application/octet-stream");
- }
- }
- $sFilesize = 0;
- if (!filesize($sPath))
- {
- if (!file_exists($sPath))
- {
- $errorOccurred = 341;
- }
- }
- else
- {
- $sFilesize = filesize($sPath);
- header("Content-Length:" . $sFilesize);
- }
- if ($sFilesize != 0)
- {
- ///////////////////////////////////////////////////
- // read file from filesystem
- ///////////////////////////////////////////////////
- $hFileHandle = fopen($sPath, 'rb');
- $iChunkSize = 1*(1024*1024);
- session_write_close();
- if ($hFileHandle === false)
- {
- $errorOccurred = 342;
- log_activity("get image", "error", return_error_text(342, "", $arErrors));
- ///////////////////////////////////////////////////
- // something's wrong with this file, it likely
- // doesn't exist, let's blow away the folder's
- // session vars so the cache won't show it.
- ///////////////////////////////////////////////////
- unset($_SESSION['currentFolder']);
- unset($_SESSION['currentFolderInfo']);
- unset($_SESSION['currentFolderFiles']);
- }
- if (fread($hFileHandle, 1024) === false)
- {
- $errorOccurred = 343;
- }
- else
- {
- rewind($hFileHandle);
- while (!feof($hFileHandle) && connection_status()==0)
- {
- $buffer = fread($hFileHandle, $iChunkSize);
- print $buffer;
- }
- }
- // we either succeeded or failed, either way, we no longer need teh file handle open
- fclose($hFileHandle);
- }
- }
- else
- {
- ///////////////////////////////////////////////////
- // We have an Internet Shortcut, let's open up
- // a new window to the URL saved in the file
- ///////////////////////////////////////////////////
- $sFileContents = file_get_contents($sPath);
- $arFileContents = explode("\r",$sFileContents);
- foreach ($arFileContents as $line)
- {
- if (strpos($line, "URL=http"))
- {
- // we've got the URL!! Let's go....
- header("location: " . substr(strrchr($line,"URL=http"),4) );
- }
- }
- echo $arFileContents[1];
- }
-
- if ($errorOccurred == 0)
- {
- log_activity("download", "success", "");
- exit;
- }
- else
- {
- log_activity("download", "failure", return_error_text($errorOccurred, "", $arErrors));
- gotoAbs('/error/' . $errorOccurred . '/return');
- exit();
- }
- }
- else
- {
- log_activity("download", "failure", return_error_text($errorOccurred, "", $arErrors));
- gotoAbs('/error/' . $errorOccurred . '/return');
- exit();
- }
- ?>